﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CpuSimulator.Instructions
{
    /// <summary>
    /// 将rs1中的值和立即数按位进行与操作，并将结果写入rd
    /// _________________________________________________________________________________________________________________________________________________
    /// |_________________立即数12位________________________|_________rs1,5位______|_Func3______|_________rd,5位______|_____OPCODE 7位____________|
    /// | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 |
    /// |                         imm[11:0]                                        |       rs1                     |    111          |        rd                      |            0010011                     |
    /// </summary>
    public class ANDI : Instruction
    {
        public override void Execute(Cpu cpuinfo)
        {
            var newVal = cpuinfo.Registers[this.Rs1].Value & this.Immediate;
            cpuinfo.Registers[this.Rd].SetValue(newVal);
            cpuinfo.InvodeRegisterChange(this.Rd, newVal.ToString("X8"));
        }
    }
}
